package com.accp.biz.impl;

import com.accp.biz.ComputerBiz;
import com.accp.dao.ComputerDao;
import com.accp.pojo.Computer;

import java.util.List;

public class ComputerBizImpl implements ComputerBiz {

    private ComputerDao computerDao;

    public void setComputerDao(ComputerDao computerDao) {
        this.computerDao = computerDao;
    }

    /**
     * 查询首页
     * @param className 类名
     * @param pageNo  页码
     * @param pageSize 每页显示条数
     * @return
     */
    @Override
    public List<Computer> selectByPage(String className, int pageNo, int pageSize) {
        List list = computerDao.selectByPage(className, pageNo, pageSize);
        return list;
    }

    /**
     * 查看下一页
     */
    @Override
    public int searchRecordsNextPage(int pageSize, String className) {
        int total = computerDao.totalPage(className);
        int pageNo = total / pageSize;
        if(total % pageSize > 0){
            pageNo++;
        }
        return pageNo;
    }

    @Override
    public boolean delectComputer(Computer computer) {
        boolean flag = false;
        if(computerDao.delectComputer(computer)){
            flag = true;
        }
        return flag;
    }

    @Override
    public Computer selectById(Integer id) {
        return computerDao.selectById(id);
    }

    @Override
    public boolean add(Computer computer) {
        boolean flag = false;
        if(computerDao.add(computer)){
            flag = true;
        }
        return flag;
    }

    @Override
    public boolean update(Computer computer) {
        boolean flag = false;
        if(computerDao.update(computer)){
            flag = true;
        }
        return flag;
    }
}
